package com.hxkj.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Create by chenwei on 2019/2/22 14:35
 */
@Component
public class AlipayConfig {
    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    public static String app_id = "2018032202425250";

    // 商户私钥，您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCnhED6OjTd+7u0ztwQAib5yT7MIzHR47c+Y+pSjtsbvRk0BDoeeK+ZmjFKRM4Nz6F1S7J6burbDUH1rCIvXbX7JPXaQmLb/qbtRrxhhrcsHvSPvOlgnEPqOP1O65ODfVJ1NXjraZ50OHSHEyu7z65LwmrNy9mRHAKpBlXrtzbdRhT+ri3uBDFJPTa0MxeV+UitbK8po+XKOoK9v4hVG14Whnv9ho58KGjmOHsMpBGOihfVbFdSdiYq7oJ97qQSm0N7/PB+MNdJrR2Ri3UkY4+DGb4fV9iODG/5msmdov4bxfb5QzfPxXv60ECMUaKIZuT4oyThkT8AFuOR0yn6cWC9AgMBAAECggEABerTDMO/mFPLFqDz/xDEZbBpKnbXzK05jNeksFPhg4JTgJXho6/prAhZU2FI0g4Siv0oidCfNSurt8zjzD6ILh3pHVOZAGJnbRxBjURf9gwF4YnvyHzcnUp0EDScGlnz7rX71nz9nudbnmXb9p9obb6pXSmlPs35fhT+Nfxb0McZUgsNDX/KNq1bviVPIGni7BuZmiMbh9rjwiffVWxW6QtI7nOq97bObFcmelA4KiM+PRCboAA3MCP4ku7/B9IT9I5XQ+94VKKKd2VXXEkF/YbYy5Fo8wPtpcLiX6QSSoDxHmscdcts/382Vn4eM9a0UFzef/toCBfzYIqXgvr3dQKBgQDafdLdA46bURO/2kcAaZmYx72Jl2qIoI7zQU5Z2EALoz4Zt3kfgNWFdGR0U94vs0YswwumYqEQl+H28cbUrE0oFNOEtY82YLLdTn75qDbFHJMvm1LIVKHYMYsu3HKeo5uR01Q4J6lCpSp+juA8JvMq2FqvBzpCRK73axGMmEAgdwKBgQDERjTguURod9J/3QNIadtIK7xy5dtnrByehTgRCjfX4bvV3LYGxSm8gM3ajD3P5w14QJ5R/TsFY8/6JCTwX6h6bzOdS16yQpBpZ+TrqF2jTcXin6ST4bzLIFurufOrmPupAaMKnWVz88IV2DyTK/CrTPA67bPD1keUg97p2AVpawKBgEeOA3u8SXzWPaiMPMqGyvW9HHauLwaVxpsl3RoRd1AYYyMa8kD9+W+eYbOzL8XhaW8JZYxVKrh7dVZhciN+Vjp1L5x7tW4ylwFhTrZGf8FoDU//B0pyZRqfhxyOt776h91nH2LQol8gJl2SPx+UBfkXKAPAUzUWt1JyLyojRoUbAoGADYZY9nNNx3UaSD1OkJraxWpeHfzA1bACeNntNx9hIbsoWmBPGsBTU+38QWcQi1b8kqDBSB0PCBwMpMwAz5+H2If5IomjCN2VXe4O1D5R1YLyc99UU+xmOgkMyBSUOerczJSUS5L0/rx5T1ALPIj2mJdApo7iqEgHvrAnmC2OkekCgYAjRirM2mqcW0udR/Abl+7y8HWCLcOsTWWJENCF2HDKNc1ot3G6lVJ6mCofjb/1I6Rt6T20fvviBqA20hQTeCNdFe6OfPkjSCxAeia3AadkLSHFV1R1ayZRdWIbCIE5zr51Sq1PciduzANAaeY0PonGI+HNx9BeWgJtx5R836u1MA==";

    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgop2ZZG0B4Zaxqb+b4hwnoEZoWf2pb0EbbV3Og24M1ARG3R8xWbADNVmyqrchHTGD5bsstrYscJ3f1y+1VWtM/4narNWxvSZrM99vea1OXhXRC2hba3G4TtvxAJi1xNd6ZEMLhw4mrphRSai4WHrCm2nqrWPJTZEL1mHjAJhnH/veLjJtdXHqEAFCAoX7fDOcBjE26BMl/6j5EjJSigwCY+yto87MgZmPqmB/IDPPLOrHgTI88rY4ePri93EvdXYOiCdu+zCpOjCIOv0bFvkj7DfsBp4KudZvkv4qrskRhKG5MxDGS0AfuC446XTefDuyzX+Qweh52lwGoVDyCQchQIDAQAB";

    // 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String notify_url = "http://hx.dev.ybjfu.com/pay/notify/recharge/alipay";

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://工程公网访问地址/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    public static String gatewayUrl = "https://openapi.alipay.com/gateway.do";

    // 支付宝网关
    public static String log_path = "C:\\";


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     * @param sWord 要写入日志里的文本内容
     */
    public static void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }



    @Value("${pay.alipay.appid}")
    public void setAPPID(String APPID) {
        this.app_id = APPID;
    }

//    @Value("${pay.alipay.rsa_private_key}")
//    public void setRsaPrivateKey(String rsaPrivateKey) {
//        this.merchant_private_key = rsaPrivateKey.replace(" ", "");
//    }
//
//    @Value("${pay.alipay.alipay_public_key}")
//    public void setAlipayPublicKey(String alipayPublicKey) {
//        this.alipay_public_key = alipayPublicKey.replace(" ", "");
//    }

    @Value("${pay.alipay.rechargeNotifyUrl}")
    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url.replace(" ", "");
    }
}
